<?php

			function feedshorten($string, $length)
			{
				// By default, an ellipsis will be appended to the end of the text.
				$suffix = '&hellip;';
			 
				// Convert 'smart' punctuation to 'dumb' punctuation, strip the HTML tags,
				// and convert all tabs and line-break characters to single spaces.
				$short_desc = trim(str_replace(array("\r","\n", "\t"), ' ', strip_tags($string)));
			 
				// Cut the string to the requested length, and strip any extraneous spaces 
				// from the beginning and end.
				$desc = trim(substr($short_desc, 0, $length));
			 
				// Find out what the last displayed character is in the shortened string
				$lastchar = substr($desc, -1, 1);
			 
				// If the last character is a period, an exclamation point, or a question 
				// mark, clear out the appended text.
				if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
			 
				// Append the text.
				$desc .= $suffix;
			 
				// Send the new description back to the page.
				return $desc;
			}
			
		echo "<div id='update'>";
		
		require_once('./lib/simplepie/autoloader.php');
		$feed = new SimplePie();
		$feed->set_feed_url('http://blog.dadannetwork.com/atom.xml');
		$feed->enable_order_by_date(false);
		$feed->handle_content_type();
		$feed->set_cache_location(APPPATH. '/cache');
		$feed->init();
		$items_per_feed = 5;
		 
		// As long as we're not trying to grab more items than the feed has, go through them one by one and add them to the array.
		for ($x = 0; $x < $feed->get_item_quantity($items_per_feed); $x++)
		{
			$first_items[] = $feed->get_item($x);
		}

		foreach($first_items as $item){
				$feed = $item->get_feed();
				
				$feed->strip_htmltags(array('img','strong'));
		 
				echo "
					<div class='blogupdate'>
						<h5><a href='".$item->get_permalink()."' target='_blank'>".$item->get_title()."</a></h5>
						
						<p>
							".feedshorten($item->get_description(), 100)."
						</p>
					</div>
				";
		}
		unset($feed);
		echo "</div>";

/* End of file blog.php */
/* Location: ./application/views/main/blog.php */
